// pages/movie/movie.js
const {titles} = require("../../static/data")
const {inTheaters,comingSoon,top250} = require("../../model/movieHome")
const {movieSearch} = require("../../model/moviehttp")
Page({
  data: {
    lists:[],
    searchmovies:[],
    keyword:''
  },
  onLoad:async function (options) {
    var lists = {};
    let https = [inTheaters,comingSoon,top250]
    for(let item of https){
      let res = await item();
      lists[item.name] = {
        res:res.data.res.slice(0,3),
        title:titles[item.name],
      }
    }
    this.setData({lists})  
    wx.setNavigationBarTitle({
      title: '光与影',
    });
  },
  onChange(event){
    // var keyword = this.data.keyword
      var keyword = event.detail;
      console.log(keyword)
    movieSearch(keyword).then(res=>{
      this.setData({
        searchmovies:res.data.res,keyword,
      })
    })
  },
})